package com.bugpool.leilema.tc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bugpool.leilema.tc.bean.entity.SysRole;
import com.bugpool.leilema.tc.bean.req.BaseReq;
import com.bugpool.leilema.tc.bean.req.RoleDataScopeReq;
import com.bugpool.leilema.tc.bean.req.RoleMenuReq;
import com.bugpool.leilema.tc.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @Description
 * @Date 2023/3/2 10:01
 * @Version 1.0
 **/

@RestController
@RequestMapping("/role")
@Api(tags = "角色控制器")
public class RoleController {


    @Resource
    private RoleService roleService;


    @GetMapping("/list")
    @ApiOperation("未分页角色列表")
    public List<SysRole> getRoleList() {
        return roleService.selectList();
    }

    @GetMapping("/pageList")
    @ApiOperation("分页角色列表")
    public Page<SysRole> pageList(BaseReq baseReq) {
        return roleService.selectPage(baseReq);
    }

    @PostMapping("/addRole")
    @ApiOperation("添加角色")
    public Boolean addRole(@RequestBody SysRole sysRole) {
        return roleService.addRole(sysRole);
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("删除角色")
    public Boolean delIds(@PathVariable List<Long> ids) {
        return roleService.delIds(ids);
    }

    @PutMapping("/updateRole")
    @ApiOperation("修改角色")
    public Boolean updateRole(@RequestBody SysRole sysRole) {
        //修改角色
        return roleService.updateRole(sysRole);
    }

    @PutMapping("/updateRoleMenu")
    @ApiOperation("更新角色功能权限")
    public Boolean updateRoleMenu(@RequestBody RoleMenuReq roleMenuReq) {
        return roleService.updateRoleMenu(roleMenuReq);
    }

    @PutMapping("/updateRoleDataScope")
    @ApiOperation("更新角色数据权限")
    public Boolean  updateRoleDataScope(@RequestBody RoleDataScopeReq roleDataScopeReq){
       return roleService.updateRoleDataScope(roleDataScopeReq);
    }



    @PutMapping("/{roleId}/{status}")
    @ApiOperation("启用禁用 角色")
    public Boolean updateRoleStatus(@PathVariable Long roleId, @PathVariable String status) {
        return   roleService.updateRoleStatus(roleId,status);
    }


}
